<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>客户管理</title>
<jsp:include page="../inc.jsp" flush="false"></jsp:include>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/plug-in/custom/selectorCrm/businessOpportunitiesSel.js"
        charset="utf-8"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/plug-in/custom/selectorCrm/customersSel.js"
        charset="utf-8"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/app/crm/contractsList.js"
        charset="utf-8"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/app/crm/contractsForm.js"
        charset="utf-8"></script>
        <script type="text/javascript"
        src="${pageContext.request.contextPath}/app/crm/contactList.js"
        charset="utf-8"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/app/crm/contactForm.js"
        charset="utf-8"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/app/crm/businessOpportunitiesList.js"
        charset="utf-8"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/app/crm/businessOpportunitiesForm.js"
        charset="utf-8"></script>
<script type="text/javascript">
Ext.onReady(function () {
    Ext.QuickTips.init();
    createForm();
    form = Ext.create('customersForm');
    form.getForm().load({
        url: getRootPath()+"/customersController/info.action",
        method: "POST",
        params: {
            id: '<%=request.getParameter("customersId")%>'
        },
        waitTitle:'提示',
        waitMsg:'正在处理您的请求,请稍候...',
        success:function(form,action){
            if(form.findField("established").getValue()!=null && form.findField("established").getValue()!="")
                form.findField("established").setValue(new Date(parseInt(form.findField("established").getValue() )).format("yyyy-MM-dd"));
            createLayout();
        }

    });

});

var  form, tabPanel;


// 创建form表单
function createForm() {
    Ext.define('customersForm', {
        extend: 'Ext.form.Panel',
        fields: new Ext.util.MixedCollection(),
        initComponent: function () {
            this.fields.add('id', new Ext.form.Hidden({
                name: 'id',
                dataIndex: 'id'
            }));


            this.fields.add('phone', new Ext.form.DisplayField({
                name: 'phone',
                dataIndex: 'phone',
                fieldLabel: '手机',
                allowBlank: true
            }));
            this.fields.add('officePhone', new Ext.form.DisplayField({
                name: 'officePhone',
                dataIndex: 'officePhone',
                fieldLabel: '办公电话',
                allowBlank: true
            }));
            this.fields.add('company', new Ext.form.DisplayField({
                name: 'company',
                dataIndex: 'company',
                fieldLabel: '公司',
                allowBlank:false
            }));
            this.fields.add('email', new Ext.form.DisplayField({
                name: 'email',
                dataIndex: 'email',
                fieldLabel: '电子邮箱',
                allowBlank: true
            }));
            this.fields.add('position', new Ext.form.DisplayField({
                name: 'position',
                dataIndex: 'position',
                fieldLabel: '职务',
                allowBlank: true
            }));
            this.fields.add('hotSpot',new Ext.form.Checkbox({
                name: 'hotSpot',
                dataIndex: 'hotSpot',
                fieldLabel: '热点',
                labelAlign: 'right',
                inputValue: 1
            }));
            this.fields.add('numberOfEmployees', new Ext.form.DisplayField({
                name: 'numberOfEmployees',
                dataIndex: 'numberOfEmployees',
                allowDecimals: false,
                decimalPrecision: null,
                fieldLabel: '职员数',
                allowBlank: true
            }));
            this.fields.add('source', new comboBox({
                name: 'source',
                dataIndex: 'source',
                fieldLabel: '来源',
                labelAlign: 'right',
                codeName: '来源',
                queryMode: 'local',
                typeAhead: false,
                forceSelection: true,
                loadingText: '正在搜索...',
                allowBlank: true,
                hideTrigger: false
            }));
            this.fields.add('annualTurnover', new Ext.form.DisplayField({
                name: 'annualTurnover',
                dataIndex: 'annualTurnover',
                allowDecimals: true,
                decimalPrecision: 2,
                fieldLabel: '年营业额',
                allowBlank: true
            }));
            this.fields.add('industry', new comboBox({
                name: 'industry',
                dataIndex: 'industry',
                fieldLabel: '行业',
                labelAlign: 'right',
                codeName: '行业',
                queryMode: 'local',
                typeAhead: false,
                forceSelection: true,
                loadingText: '正在搜索...',
                allowBlank: true,
                hideTrigger: false
            }));
            this.fields.add('registeredCapital', new Ext.form.DisplayField({
                name: 'registeredCapital',
                dataIndex: 'registeredCapital',
                allowDecimals: true,
                decimalPrecision: 2,
                fieldLabel: '注册资金',
                allowBlank: true
            }));
            this.fields.add('established', new Ext.form.DisplayField({
                name: 'established',
                dataIndex: 'established',
                fieldLabel: '成立时间',
                format:'Y-m-d',
                allowBlank: false
            }));
            this.fields.add('type', new comboBox({
                name: 'type',
                dataIndex: 'type',
                fieldLabel: '类型',
                labelAlign: 'right',
                codeName: '客户类型',
                queryMode: 'local',
                typeAhead: false,
                forceSelection: true,
                loadingText: '正在搜索...',
                allowBlank: true,
                hideTrigger: false
            }));

            this.fields.add('remark', new Ext.form.TextArea({
                name: 'remark',
                dataIndex: 'remark',
                fieldLabel: '备注',
                allowBlank: true
            }));

            this.items = [ this.fields.get('id'), {
                xtype: 'fieldset',
                title: '潜在客户信息',
                collapsible: true,
                defaults: {
                    labelWidth: 89,
                    anchor: '100%',
                    layout: {
                        type: 'hbox',
                        defaultMargins: {top: 0, right: 5, bottom: 0, left: 0}
                    }
                },
                items: [{
                    xtype: 'container',
                    layout: 'hbox', defaults: {
                        flex: 1,
                        hideLabel: true
                    },
                    margin: '0 0 5 0',
                    items:  [ this.fields.get('company'),this.fields.get('phone')]},
                    , {
                        xtype: 'container',
                        layout: 'hbox', defaults: {
                            flex: 1,
                            hideLabel: true
                        },
                        margin: '0 0 5 0',
                        items: [ this.fields.get('officePhone'), this.fields.get('email')]}, {
                        xtype: 'container',
                        layout: 'hbox',
                        defaults: {
                            flex: 1,
                            hideLabel: true
                        },
                        margin: '0 0 5 0',
                        items: [ this.fields.get('position'), this.fields.get('hotSpot')]}
                ]},
                {
                    xtype: 'fieldset',
                    title: '其他信息',
                    collapsible: true,
                    defaults: {
                        labelWidth: 89,
                        anchor: '100%',
                        layout: {
                            type: 'hbox',
                            defaultMargins: {top: 0, right: 5, bottom: 0, left: 0}
                        }
                    },
                    items: [
                        {
                            xtype: 'container',
                            layout: 'hbox',
                            margin: '0 0 5 0',
                            defaults: {
                                flex: 1,
                                hideLabel: true
                            },
                            items: [ this.fields.get('type'),this.fields.get('website')]}, {
                            xtype: 'container',
                            layout: 'hbox',
                            defaults: {
                                flex: 1,
                                hideLabel: true
                            },
                            margin: '0 0 5 0',
                            items: [ this.fields.get('numberOfEmployees'), this.fields.get('annualTurnover')]},

                        {
                            xtype: 'container',
                            layout: 'hbox',
                            margin: '0 0 5 0',
                            defaults: {
                                flex: 1,
                                hideLabel: true
                            },
                            items: [  this.fields.get('source') ,this.fields.get('industry')]},
                        {
                            xtype: 'container',
                            layout: 'hbox',
                            margin: '0 0 5 0',
                            defaults: {
                                flex: 1,
                                hideLabel: true
                            },
                            items: [ this.fields.get('registeredCapital'),this.fields.get('established')]}


                    ]},
                {
                    xtype: 'fieldset',
                    title: '地址信息',
                    collapsible: true,
                    defaults: {
                        labelWidth: 89,
                        anchor: '100%',
                        layout: {
                            type: 'hbox',
                            defaultMargins: {top: 0, right: 5, bottom: 0, left: 0}
                        }
                    },
                    items: [
                        {
                            xtype : 'textfield',
                            name : 'billingZipCode',
                            dataIndex : 'billingZipCode',
                            fieldLabel : '开单邮编',
                            allowBlank : true
                        },
                        {
                            xtype : 'textfield',
                            name : 'billingAddress',
                            dataIndex : 'billingAddress',
                            fieldLabel : '开单地址',
                            allowBlank : true
                        },
                        {
                            xtype : 'textfield',
                            name : 'shipZipCode',
                            dataIndex : 'shipZipCode',
                            fieldLabel : '发货邮编',
                            allowBlank : true
                        },
                        {
                            xtype : 'textfield',
                            name : 'shipAddress',
                            dataIndex : 'shipAddress',
                            fieldLabel : '发货地址',
                            allowBlank : true
                        }
                    ]},
                {
                    xtype: 'fieldset',
                    title: '备注',
                    collapsible: true,
                    defaults: {
                        labelWidth: 89,
                        anchor: '100%',
                        layout: {
                            type: 'hbox',
                            defaultMargins: {top: 0, right: 5, bottom: 0, left: 0}
                        }
                    },
                    items: [this.fields.get('remark')]}];
            this.xtype = 'form';
            this.frame = false;
            this.border = false;
            this.split = true;
            this.bodyPadding = 10,
                    this.autoScroll = true,//自动出滚动条
                    this.bodyBorder = true;
            this.fieldDefaults = {
                labelWidth: 80,
                labelAlign: 'right',
                msgTarget: 'side'
            };
            this.defaults = {
                anchor: '100%'
            };
            this.callParent(arguments);
        },
        onRender: function () {
            this.callParent(arguments);
        },
        newDataRecord: function () {
            this.getForm().reset();
        }
    });
}
// 创建layout
function createLayout() {
    tabPanel= Ext.create('Ext.tab.Panel', {
        activeTab: 0,                       //指定默认的活动tab
        plain: true,                        //True表示tab候选栏上没有背景图片（默认为false）
        enableTabScroll: true,              //选项卡过多时，允许滚动
        defaults: { autoScroll: true },
        layout: 'fit',
        listeners:{
            tabchange:function(tp,p){

            }
        } ,
        items: [{
            id: "tab1",
            title: '详细信息',
            items:[form],
            closable: false                  //这个tab可以被关闭
        }
            ,{
                id: "tab2",
                layout: 'fit',
                title: '联系人',
                items:[Ext.create('App.crm.contactList')]
               // html : '<iframe scrolling="auto" frameborder="0"   width="100%" height="100%" src="contact.jsp?customersId='+form.getForm().findField("id").getValue()+'&customersName='+form.getForm().findField("company").getValue()+'"></iframe>'
            },{
            id: "tab3",
            layout: 'fit',
            title: '计划的活动',
            html : '<iframe scrolling="auto" frameborder="0"   width="100%" height="100%" src="programActivities.jsp?entityId='+form.getForm().findField("id").getValue()+'"></iframe>'
        } ,{
            id: "tab4",
            layout: 'fit',
            title: '业务机会',
            items:[Ext.create('App.crm.businessOpportunitiesList')]
           // html : '<iframe scrolling="auto" frameborder="0"   width="100%" height="100%" src="businessOpportunities.jsp?customersId='+form.getForm().findField("id").getValue()+'&customersName='+form.getForm().findField("company").getValue()+'"></iframe>'
        },{
                id: "tab5",
                layout: 'fit',
                title: '合同',
                items:[Ext.create('App.crm.contractsList')]
            }, {
            id: "tab6",
            title: '附件',
            html : '<iframe scrolling="auto" frameborder="0"   width="100%" height="100%" src="${pageContext.request.contextPath}/upload/attachment.jsp?customersId='+form.getForm().findField("id").getValue()+'"></iframe>'
        },{
            id: "tab7",
            title: '通信历史',

            html : '<iframe scrolling="auto" frameborder="0"   width="100%" height="100%" src="communicationHistory.jsp?businessKey='+form.getForm().findField("id").getValue()+'&receptionName='+form.getForm().findField("company").getValue()+'&phone='+form.getForm().findField("phone").getValue()+'&email=' +form.getForm().findField("email").getValue()+'"></iframe>'
        }]
    });
    
   
    var viewport = new Ext.Viewport({
        layout: 'fit',
        region: 'center',
        border: false,
        items: [
            tabPanel
        ]
    });
    viewport.doLayout();
}
</script>
</head>
<body>
</body>
</html>